home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / hyperspt.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  8KB  |  330 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *hyperspt_scroll;
  14. static int flipscreen;
  15.  
  16.  
  17.  
  18. /***************************************************************************
  19.  
  20.   Convert the color PROMs into a more useable format.
  21.  
  22.   Hyper Sports has one 32x8 palette PROM and two 256x4 lookup table PROMs
  23.   (one for characters, one for sprites).
  24.   The palette PROM is connected to the RGB output this way:
  25.  
  26.   bit 7 -- 220 ohm resistor  -- BLUE
  27.         -- 470 ohm resistor  -- BLUE
  28.         -- 220 ohm resistor  -- GREEN
  29.         -- 470 ohm resistor  -- GREEN
  30.         -- 1  kohm resistor  -- GREEN
  31.         -- 220 ohm resistor  -- RED
  32.         -- 470 ohm resistor  -- RED
  33.   bit 0 -- 1  kohm resistor  -- RED
  34.  
  35. ***************************************************************************/
  36. void hyperspt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  37. {
  38.     int i;
  39.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  40.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  41.  
  42.  
  43.     for (i = 0;i < Machine->drv->total_colors;i++)
  44.     {
  45.         int bit0,bit1,bit2;
  46.  
  47.  
  48.         /* red component */
  49.         bit0 = (*color_prom >> 0) & 0x01;
  50.         bit1 = (*color_prom >> 1) & 0x01;
  51.         bit2 = (*color_prom >> 2) & 0x01;
  52.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  53.         /* green component */
  54.         bit0 = (*color_prom >> 3) & 0x01;
  55.         bit1 = (*color_prom >> 4) & 0x01;
  56.         bit2 = (*color_prom >> 5) & 0x01;
  57.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  58.         /* blue component */
  59.         bit0 = 0;
  60.         bit1 = (*color_prom >> 6) & 0x01;
  61.         bit2 = (*color_prom >> 7) & 0x01;
  62.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  63.  
  64.         color_prom++;
  65.     }
  66.  
  67.     /* color_prom now points to the beginning of the lookup table */
  68.  
  69.  
  70.     /* sprites */
  71.     for (i = 0;i < TOTAL_COLORS(1);i++)
  72.         COLOR(1,i) = *(color_prom++) & 0x0f;
  73.  
  74.     /* characters */
  75.     for (i = 0;i < TOTAL_COLORS(0);i++)
  76.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
  77. }
  78.  
  79.  
  80.  
  81. /***************************************************************************
  82.  
  83.   Start the video hardware emulation.
  84.  
  85. ***************************************************************************/
  86. int hyperspt_vh_start(void)
  87. {
  88.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  89.         return 1;
  90.     memset(dirtybuffer,1,videoram_size);
  91.  
  92.     /* Hyper Sports has a virtual screen twice as large as the visible screen */
  93.     if ((tmpbitmap = osd_create_bitmap(2 * Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  94.     {
  95.         free(dirtybuffer);
  96.         return 1;
  97.     }
  98.  
  99.     return 0;
  100. }
  101.  
  102.  
  103.  
  104. /***************************************************************************
  105.  
  106.   Stop the video hardware emulation.
  107.  
  108. ***************************************************************************/
  109. void hyperspt_vh_stop(void)
  110. {
  111.     free(dirtybuffer);
  112.     osd_free_bitmap(tmpbitmap);
  113. }
  114.  
  115.  
  116.  
  117. WRITE_HANDLER( hyperspt_flipscreen_w )
  118. {
  119.     if (flipscreen != (data & 1))
  120.     {
  121.         flipscreen = data & 1;
  122.         memset(dirtybuffer,1,videoram_size);
  123.     }
  124. }
  125.  
  126.  
  127.  
  128. /***************************************************************************
  129.  
  130.   Draw the game screen in the given osd_bitmap.
  131.   Do NOT call osd_update_display() from this function, it will be called by
  132.   the main emulation engine.
  133.  
  134. ***************************************************************************/
  135. void hyperspt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  136. {
  137.     int offs;
  138.  
  139.  
  140.     /* for every character in the Video RAM, check if it has been modified */
  141.     /* since last time and update it accordingly. */
  142.     for (offs = videoram_size - 1;offs >= 0;offs--)
  143.     {
  144.         if (dirtybuffer[offs])
  145.         {
  146.             int sx,sy,flipx,flipy;
  147.  
  148.  
  149.             dirtybuffer[offs] = 0;
  150.  
  151.             sx = offs % 64;
  152.             sy = offs / 64;
  153.             flipx = colorram[offs] & 0x10;
  154.             flipy = colorram[offs] & 0x20;
  155.             if (flipscreen)
  156.             {
  157.                 sx = 63 - sx;
  158.                 sy = 31 - sy;
  159.                 flipx = !flipx;
  160.                 flipy = !flipy;
  161.             }
  162.  
  163.             drawgfx(tmpbitmap,Machine->gfx[0],
  164.                     videoram[offs] + ((colorram[offs] & 0x80) << 1) + ((colorram[offs] & 0x40) << 3),
  165.                     colorram[offs] & 0x0f,
  166.                     flipx,flipy,
  167.                     8*sx,8*sy,
  168.                     0,TRANSPARENCY_NONE,0);
  169.         }
  170.     }
  171.  
  172.  
  173.     /* copy the temporary bitmap to the screen */
  174.     {
  175.         int scroll[32];
  176.  
  177.  
  178.         if (flipscreen)
  179.         {
  180.             for (offs = 0;offs < 32;offs++)
  181.                 scroll[31-offs] = 256 - (hyperspt_scroll[2*offs] + 256 * (hyperspt_scroll[2*offs+1] & 1));
  182.         }
  183.         else
  184.         {
  185.             for (offs = 0;offs < 32;offs++)
  186.                 scroll[offs] = -(hyperspt_scroll[2*offs] + 256 * (hyperspt_scroll[2*offs+1] & 1));
  187.         }
  188.  
  189.         copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  190.  
  191.     }
  192.  
  193.  
  194.     /* Draw the sprites. */
  195.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  196.     {
  197.         int sx,sy,flipx,flipy;
  198.  
  199.  
  200.         sx = spriteram[offs + 3];
  201.         sy = 240 - spriteram[offs + 1];
  202.         flipx = ~spriteram[offs] & 0x40;
  203.         flipy = spriteram[offs] & 0x80;
  204.         if (flipscreen)
  205.         {
  206.             sy = 240 - sy;
  207.             flipy = !flipy;
  208.         }
  209.  
  210.         /* Note that this adjustement must be done AFTER handling flipscreen, thus */
  211.         /* proving that this is a hardware related "feature" */
  212.         sy += 1;
  213.  
  214.         drawgfx(bitmap,Machine->gfx[1],
  215.                 spriteram[offs + 2] + 8 * (spriteram[offs] & 0x20),
  216.                 spriteram[offs] & 0x0f,
  217.                 flipx,flipy,
  218.                 sx,sy,
  219.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  220.  
  221.         /* redraw with wraparound */
  222.         drawgfx(bitmap,Machine->gfx[1],
  223.                 spriteram[offs + 2] + 8 * (spriteram[offs] & 0x20),
  224.                 spriteram[offs] & 0x0f,
  225.                 flipx,flipy,
  226.                 sx-256,sy,
  227.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  228.     }
  229. }
  230.  
  231.  
  232.  
  233. /* Only difference with Hyper Sports is the way tiles are selected (1536 tiles */
  234. /* instad of 1024). Plus, it has 256 sprites instead of 512. */
  235. void roadf_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  236. {
  237.     int offs;
  238.  
  239.  
  240.     /* for every character in the Video RAM, check if it has been modified */
  241.     /* since last time and update it accordingly. */
  242.     for (offs = videoram_size - 1;offs >= 0;offs--)
  243.     {
  244.         if (dirtybuffer[offs])
  245.         {
  246.             int sx,sy,flipx,flipy;
  247.  
  248.  
  249.             dirtybuffer[offs] = 0;
  250.  
  251.             sx = offs % 64;
  252.             sy = offs / 64;
  253.             flipx = colorram[offs] & 0x10;
  254.             flipy = 0;    /* no vertical flip */
  255.             if (flipscreen)
  256.             {
  257.                 sx = 63 - sx;
  258.                 sy = 31 - sy;
  259.                 flipx = !flipx;
  260.                 flipy = !flipy;
  261.             }
  262.  
  263.             drawgfx(tmpbitmap,Machine->gfx[0],
  264.                     videoram[offs] + ((colorram[offs] & 0x80) << 1) + ((colorram[offs] & 0x60) << 4),
  265.                     colorram[offs] & 0x0f,
  266.                     flipx,flipy,
  267.                     8*sx,8*sy,
  268.                     0,TRANSPARENCY_NONE,0);
  269.         }
  270.     }
  271.  
  272.  
  273.     /* copy the temporary bitmap to the screen */
  274.     {
  275.         int scroll[32];
  276.  
  277.  
  278.         if (flipscreen)
  279.         {
  280.             for (offs = 0;offs < 32;offs++)
  281.                 scroll[31-offs] = 256 - (hyperspt_scroll[2*offs] + 256 * (hyperspt_scroll[2*offs+1] & 1));
  282.         }
  283.         else
  284.         {
  285.             for (offs = 0;offs < 32;offs++)
  286.                 scroll[offs] = -(hyperspt_scroll[2*offs] + 256 * (hyperspt_scroll[2*offs+1] & 1));
  287.         }
  288.  
  289.         copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  290.  
  291.     }
  292.  
  293.  
  294.     /* Draw the sprites. */
  295.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  296.     {
  297.         int sx,sy,flipx,flipy;
  298.  
  299.  
  300.         sx = spriteram[offs + 3];
  301.         sy = 240 - spriteram[offs + 1];
  302.         flipx = ~spriteram[offs] & 0x40;
  303.         flipy = spriteram[offs] & 0x80;
  304.         if (flipscreen)
  305.         {
  306.             sy = 240 - sy;
  307.             flipy = !flipy;
  308.         }
  309.  
  310.         /* Note that this adjustement must be done AFTER handling flipscreen, thus */
  311.         /* proving that this is a hardware related "feature" */
  312.         sy += 1;
  313.  
  314.         drawgfx(bitmap,Machine->gfx[1],
  315.                 spriteram[offs + 2] + 8 * (spriteram[offs] & 0x20),
  316.                 spriteram[offs] & 0x0f,
  317.                 flipx,flipy,
  318.                 sx,sy,
  319.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  320.  
  321.         /* redraw with wraparound (actually not needed in Road Fighter) */
  322.         drawgfx(bitmap,Machine->gfx[1],
  323.                 spriteram[offs + 2] + 8 * (spriteram[offs] & 0x20),
  324.                 spriteram[offs] & 0x0f,
  325.                 flipx,flipy,
  326.                 sx-256,sy,
  327.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  328.     }
  329. }
  330.